package 试题和试卷;

import GUI.organizePaperWindow;

import javax.swing.text.html.HTMLDocument;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;

public class subjectiveAddItem extends questionAddItem {
    public subjectiveAddItem() {
    }

    public subjectiveAddItem(int n, question currentquestion) {

        super(n, currentquestion);
        detailButton.addActionListener(new detailListener());
        deleteButton.addActionListener(new deleteListener());

    }

    public class detailListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            organizePaperWindow.subjectiveQuestions.add((subjectiveQuestion) currentquestion);
            organizePaperWindow.questions.add((subjectiveQuestion) currentquestion);
            detailButton.setEnabled(false);
            deleteButton.setEnabled(true);
        }
    }
    public class deleteListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            //int size=organizePaperWindow.subjectiveQuestions.size();
            organizePaperWindow.subjectiveQuestions.removeIf(a -> currentquestion.getTitle().equals(a.getTitle()));
            organizePaperWindow.questions.removeIf(a ->currentquestion.getTitle().equals(a.getTitle()));
            /*for (int i=0;i<size;i++){
                if(currentquestion.getTitle()==organizePaperWindow.subjectiveQuestions.get(i).getTitle()){
                    organizePaperWindow.subjectiveQuestions.remove(i);
                    organizePaperWindow.questions.remove(i);
                }
            }*/
            detailButton.setEnabled(true);
            deleteButton.setEnabled(false);
        }
    }
}